﻿using System;
using System.Collections.Generic;
using System.Runtime.InteropServices;
 
using System.Text;


namespace HDF5
{
    using hid_t = System.Int32;
    using herr_t = System.Int32;
    using hsize_t = System.UInt64;
    using hssize_t = System.Int64;
    using hunsigned = System.UInt32;


    using hbool_t = System.UInt32;
    using htri_t = System.Int32;
    using sszie_t = System.Int64;

    using haddr_t = System.UInt64;

    using uint32_t = System.UInt32;
    using uint64_t = System.UInt64;

    using H5O_msg_crt_idx_t = System.UInt32;

    using size_t = System.UInt32;


    #region enums
    /* Values for the H5D_LAYOUT property */
    public enum H5D_layout_t {
        H5D_LAYOUT_ERROR	= -1,

        H5D_COMPACT		= 0,	/*raw data is very small		     */
        H5D_CONTIGUOUS	= 1,	/*the default				     */
        H5D_CHUNKED		= 2,	/*slow and fancy			     */
        H5D_NLAYOUTS	= 3	/*this one must be last!		     */
    }  

    /* Types of chunk index data structures */
    public enum H5D_chunk_index_t {
        H5D_CHUNK_BTREE	= 0	/* v1 B-tree index			     */
    }  

    /* Values for the space allocation time property */
    public enum H5D_alloc_time_t {
        H5D_ALLOC_TIME_ERROR	= -1,
        H5D_ALLOC_TIME_DEFAULT  	= 0,
        H5D_ALLOC_TIME_EARLY	= 1,
        H5D_ALLOC_TIME_LATE		= 2,
        H5D_ALLOC_TIME_INCR		= 3
    }  

    /* Values for the status of space allocation */
    public enum H5D_space_status_t {
        H5D_SPACE_STATUS_ERROR		= -1,
        H5D_SPACE_STATUS_NOT_ALLOCATED	= 0,
        H5D_SPACE_STATUS_PART_ALLOCATED	= 1,
        H5D_SPACE_STATUS_ALLOCATED		= 2
    }  

    /* Values for time of writing fill value property */
    public enum H5D_fill_time_t {
        H5D_FILL_TIME_ERROR	= -1,
        H5D_FILL_TIME_ALLOC = 0,
        H5D_FILL_TIME_NEVER	= 1,
        H5D_FILL_TIME_IFSET	= 2
    }  

    /* Values for fill value status */
    public enum H5D_fill_value_t {
        H5D_FILL_VALUE_ERROR        =-1,
        H5D_FILL_VALUE_UNDEFINED    =0,
        H5D_FILL_VALUE_DEFAULT      =1,
        H5D_FILL_VALUE_USER_DEFINED =2
    }

    #endregion enums


    public delegate herr_t H5D_operator_t(IntPtr elem, hid_t type_id, hunsigned ndim,ref hsize_t point, IntPtr operator_data);

    public static class H5D
    {
        public static size_t H5D_CHUNK_CACHE_NSLOTS_DEFAULT =    unchecked((size_t)( -1));
        public static size_t H5D_CHUNK_CACHE_NBYTES_DEFAULT = unchecked((size_t)(-1));
        public static int H5D_CHUNK_CACHE_W0_DEFAULT = -1;
        /// <summary>
        /// import H5D Datasets
        /// </summary>
           


        [DllImport("hdf5dll.dll",CharSet=CharSet.Ansi)]
        public static extern hid_t H5Dcreate( hid_t loc_id, [In][MarshalAs(UnmanagedType.LPStr)] string name, hid_t type_id, hid_t space_id, hid_t dcpl_id ) ;

        [DllImport("hdf5dll.dll",CharSet=CharSet.Ansi)]
        public static extern hid_t H5Dcreate( hid_t loc_id, [In][MarshalAs(UnmanagedType.LPStr)] string name, hid_t dtype_id, hid_t space_id, hid_t lcpl_id, hid_t dcpl_id, hid_t dapl_id )  ;

        [DllImport("hdf5dll.dll",CharSet=CharSet.Ansi)]
        public static extern hid_t H5Dcreate2( hid_t loc_id, [In][MarshalAs(UnmanagedType.LPStr)] string name, hid_t dtype_id, hid_t space_id, hid_t lcpl_id, hid_t dcpl_id, hid_t dapl_id )  ;

        [DllImport("hdf5dll.dll",CharSet=CharSet.Ansi)]
        public static extern hid_t H5Dcreate_anon( hid_t loc_id, hid_t type_id, hid_t space_id, hid_t dcpl_id, hid_t dapl_id )  ;

        [DllImport("hdf5dll.dll",CharSet=CharSet.Ansi)]
        public static extern hid_t H5Dopen( hid_t loc_id, [In][MarshalAs(UnmanagedType.LPStr)] string name )  ;

        [DllImport("hdf5dll.dll",CharSet=CharSet.Ansi)]
        public static extern hid_t H5Dopen( hid_t loc_id, [In][MarshalAs(UnmanagedType.LPStr)] string name, hid_t dapl_id )  ;

        [DllImport("hdf5dll.dll",CharSet=CharSet.Ansi)]
        public static extern  hid_t H5Dopen2( hid_t loc_id, [In][MarshalAs(UnmanagedType.LPStr)] string name, hid_t dapl_id ) ;

        [DllImport("hdf5dll.dll",CharSet=CharSet.Ansi)]
        public static extern herr_t H5Dclose(hid_t dataset_id )  ;

        [DllImport("hdf5dll.dll",CharSet=CharSet.Ansi)]
        public static extern hid_t H5Dget_space(hid_t dataset_id )  ;

        [DllImport("hdf5dll.dll",CharSet=CharSet.Ansi)]
        public static extern herr_t H5Dget_space_status(hid_t dset_id, out H5D_space_status_t status)  ;

        [DllImport("hdf5dll.dll",CharSet=CharSet.Ansi)]
        public static extern  hid_t H5Dget_type(hid_t dataset_id ) ;

        [DllImport("hdf5dll.dll",CharSet=CharSet.Ansi)]
        public static extern hid_t H5Dget_create_plist(hid_t dataset_id )  ;

        [DllImport("hdf5dll.dll",CharSet=CharSet.Ansi)]
        public static extern hid_t H5Dget_access_plist( hid_t dataset_id )  ;

        [DllImport("hdf5dll.dll",CharSet=CharSet.Ansi)]
        public static extern haddr_t H5Dget_offset( hid_t dset_id )  ;

        [DllImport("hdf5dll.dll",CharSet=CharSet.Ansi)]
        public static extern hsize_t H5Dget_storage_size(hid_t dataset_id )  ;

        [DllImport("hdf5dll.dll",CharSet=CharSet.Ansi)]
        public static extern herr_t H5Dvlen_get_buf_size(hid_t dataset_id, hid_t type_id, hid_t space_id, out hsize_t size )  ;

        [DllImport("hdf5dll.dll",CharSet=CharSet.Ansi)]
        public static extern herr_t H5Dvlen_reclaim(hid_t type_id, hid_t space_id, hid_t plist_id, IntPtr buf )  ;

        [DllImport("hdf5dll.dll",CharSet=CharSet.Ansi)]
        public static extern  herr_t H5Dread(hid_t dataset_id, hid_t mem_type_id, hid_t mem_space_id, hid_t file_space_id, hid_t xfer_plist_id, IntPtr buf ) ;

        [DllImport("hdf5dll.dll",CharSet=CharSet.Ansi)]
        public static extern  herr_t H5Dwrite(hid_t dataset_id, hid_t mem_type_id, hid_t mem_space_id, hid_t file_space_id, hid_t xfer_plist_id, IntPtr buf ) ;

        [DllImport("hdf5dll.dll",CharSet=CharSet.Ansi)]
        public static extern herr_t H5Diterate( IntPtr buf, hid_t type_id, hid_t space_id, H5D_operator_t op, IntPtr operator_data )  ;

        [DllImport("hdf5dll.dll",CharSet=CharSet.Ansi)]
        public static extern herr_t H5Dset_extent( hid_t dset_id, hsize_t[] size )  ;

        [DllImport("hdf5dll.dll",CharSet=CharSet.Ansi)]
        public static extern herr_t H5Dfill( IntPtr fill, hid_t fill_type_id, IntPtr buf, hid_t buf_type_id, hid_t space_id )  ;




    }
}
